// 封装 toast 弹窗
export const Toast = (e, iconType, times, mask) => {
	uni.showToast({
		title: e,
		mask: mask ? mask : false,
		icon: iconType ? iconType : 'none',
		duration: times ? times : 1500
	})
}

/**
 * 处理密钥字符格式
 * @param: key 需要转格式的字符
 */
export const encParse = key =>{
    // key = CryptoJs.enc.Utf8.parse(key);
    return CryptoJs.enc.Latin1.parse(key);
}


/**
 * 对象深拷贝
 */
export const deepClone = data => {
	var type = getObjType(data)
	var obj
	if (type === 'array') {
		obj = []
	} else if (type === 'object') {
		obj = {}
	} else {
		// 不再具有下一层次
		return data
	}
	if (type === 'array') {
		for (var i = 0, len = data.length; i < len; i++) {
			obj.push(deepClone(data[i]))
		}
	} else if (type === 'object') {
		for (var key in data) {
			obj[key] = deepClone(data[key])
		}
	}
	return obj
}

export const getObjType = obj => {
	var toString = Object.prototype.toString
	var map = {
		'[object Boolean]': 'boolean',
		'[object Number]': 'number',
		'[object String]': 'string',
		'[object Function]': 'function',
		'[object Array]': 'array',
		'[object Date]': 'date',
		'[object RegExp]': 'regExp',
		'[object Undefined]': 'undefined',
		'[object Null]': 'null',
		'[object Object]': 'object'
	}
	return map[toString.call(obj)]
}



// 退出登录
export const logout = () => {
	// 清空所有缓存
	uni.removeStorageSync('token')
	uni.removeStorageSync('refreshToken')
	uni.showToast({
		title: "",
		icon: "loading",
		mask: true,
		duration: 500,
		success: () => {
			uni.reLaunch({
				url: ""
			})
		}
	})
}